#! /bin/sh

cat <<EOF
`echo "(1) basecenter"`
`echo "(2) maindatacenter"`
`echo "(3) operatecenter"`
`echo "(4) businessapp"`
`echo "(0) quit"`
EOF

prepare_image() {
  echo "Remove existing image of ${1}..."
  docker rmi "0.0.0.0:8088/businesscenter/${1}:uat"

  echo "Pull image of ${1} from repository..."
  docker pull "0.0.0.0:8088/businesscenter/${1}:uat"

  echo "Save image to ${1}.jar ..."
  cd /home/test/files/files
  docker save -o "${1}.jar" "0.0.0.0:8088/businesscenter/${1}:uat"

  chmod 775 "/home/test/files/files/${1}.jar"
  echo "Prepare ${1} done"
}

read -p "Please input service number": num
case $num in
  (1)
  prepare_image basecenter
  prepare_image maindatacenter
  prepare_image operatecenter
  prepare_image businessapp
  ;;
  (2)
  prepare_image maindatacenter
  prepare_image operatecenter
  prepare_image businessapp
  ;;
  (3)
  prepare_image operatecenter
  prepare_image businessapp
  ;;
  (4)
  prepare_image businessapp
  ;;
  (0)
  exit 0
esac
